﻿/*
 * 2008 (c) ralfoide at gmail com
 * Project: SharpFlow
 * License: GPL
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Alfray.SharpFlow.Utils;
using Alfray.SharpFlow.Core;
using System.Collections;

namespace Alfray.SharpFlow.UI {
    /// <summary>
    /// Form that displays the preference window.
    /// </summary>
    public partial class PreferencesForm : AutoSavingForm {
        public PreferencesForm() {
            InitializeComponent();

            initFIList();
        }

        private void mCloseButton_Click(object sender, EventArgs e) {
            Visible = false;
        }

        private void initFIList() {
            DataCore dc = DataCore.singleton;

            List<FI> fis = dc.getFIList();
            fis.Sort();

            foreach (FI f in fis) {
                mFIListBox.Items.Add(f);
            }

            FI current_fi = dc.getCurrentFI();
            if (current_fi != null) {
                mFIListBox.SelectedItem = current_fi;

                dc.logger.append("Pref: selected FI '{0}' at index {1}",
                    current_fi.ToFullString(),
                    mFIListBox.SelectedIndex);
            }
        }

        private void mFIListBox_SelectedIndexChanged(object sender, EventArgs e) {
            DataCore dc = DataCore.singleton;
            FI selected = mFIListBox.SelectedItem as FI;
            dc.setCurrentFI(selected);
            dc.logger.append("Pref: set current FI to {0}",
                mFIListBox.SelectedItem == null ? "null" : selected.ToFullString());
        }
    }
}
